package cn.fl.audit.service.impl;

import java.util.*;

import cn.cmm.base.framework.utils.*;
import cn.fl.audit.vo.*;
import cn.fl.preloan.IAuditReturnVisitService;
import cn.fl.preloan.condition.AuditReturnVisitQueryCondition;
import cn.fl.preloan.dto.audit.*;
import cn.fl.commons.result.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.fl.audit.condition.AudReturnVisitQueryCondition;
import cn.fl.audit.constant.AudStandingBookConstant;
import cn.fl.audit.dto.AudOpeLineDTO;
import cn.fl.audit.dto.AudReturnVisitDTO;
import cn.fl.audit.service.IAudReturnVisitService;
import cn.fl.audit.service.IAuditApiService;
import cn.fl.audit.transform.AudReturnVisitVOTransform;
import cn.fl.audit.transform.AudOpeLineVOTransform;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.condition.PrjCstBscInfoQueryCondition;
import cn.fl.project.condition.PrjLinkManQueryCondition;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.condition.PrjQuatPrpsQueryCondition;
import cn.fl.project.constant.PrjCstBscInfoConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstBscInfoService;
import cn.fl.project.service.IPrjLinkManService;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.service.IPrjQuatPrpsService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstBscInfoVO;
import cn.fl.project.vo.PrjLinkManVO;
import cn.fl.project.vo.PrjPrdDtlVO;
import cn.fl.project.vo.PrjQuatPrpsVO;
import fl.riskctrl.facade.riskctrl.acard.api.IRcACardSearchApiService;
import fl.riskctrl.facade.riskctrl.acard.condition.RcCpModExtInfoQC;
import fl.riskctrl.facade.riskctrl.acard.dto.RcCpModExtInfoDTO;

/**
 * @Description: 信审回访表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AudReturnVisitServiceImpl implements IAudReturnVisitService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(AudReturnVisitServiceImpl.class);

	/**
	 */
	@Autowired
	private IAuditApiService auditApiService;

	/**
	 * 数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	/**
	 * 项目客户信息服务
	 */
	@Autowired
	private IPrjCstBscInfoService prjCstBscInfoService;

	/**
	 * 客户基础信息服务
	 */
	@Autowired
	private ICstBscInfoService cstBscInfoService;

	/**
	 * 项目产品明细服务
	 */
	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;

	/**
	 * 项目报价方案服务
	 */
	@Autowired
	private IPrjQuatPrpsService prjQuatPrpsService;

	/**
	 * 项目联系人信息服务
	 */
	@Autowired
	private IPrjLinkManService prjLinkManService;
	@Autowired
	private IRcACardSearchApiService rcACardSearchApiService;

    @Autowired
    private IAuditReturnVisitService auditReturnVisitService;

    @Override
	public AudReturnVisitVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AudReturnVisitDTO dto = null;//this.自定义ApiService.selectById(id);
		return AudReturnVisitVOTransform.toVO(dto);
	}
	/*
     * 项目信息服务
     */
    @Autowired
    private IPrjBscInfoService prjBscInfoService;
	@Override
	public Long add(AudReturnVisitVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//Holly
		if(StringUtils.isNotEmpty(entity.getProjectId())) {
			PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(entity.getProjectId());
			if(prjBscInfoVO!=null) {
				String cstMgrNm = prjBscInfoVO.getCstMgrNm();
				if(StringUtils.isNotEmpty(cstMgrNm)) {
					entity.setAccountManagerNm(cstMgrNm);
				}
			}
		}
		return this.auditApiService.addAudReturnVisit(AudReturnVisitVOTransform.toDTO(entity));
	}
	@Override
	public Long addOperateLine(AudOpeLineVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.auditApiService.addAudOpeLine(AudOpeLineVOTransform.toDTO(entity));
	}
	/*
	 * (non-Javadoc)修改运营路线
	 * @see cn.fl.audit.service.IAudReturnVisitService#updateOperateLine(cn.fl.audit.vo.AudOpeLineVO)
	 */
	@Override
	public Long updateOperateLine(AudOpeLineVO audOpeLineVO2) throws BaseException{
		if(null == audOpeLineVO2){
			BaseLogUtils.info(logger, "add", "修改对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AudOpeLineDTO dto = AudOpeLineVOTransform.toDTO(audOpeLineVO2);
		return this.auditApiService.updateAudOpeLine(dto);

	}
	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.audReturnVisitApiService.removeById(id);
		return false;
	}

	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(AudReturnVisitVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.auditApiService.modifyAudReturnVisit(AudReturnVisitVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
	}

    @SuppressWarnings("unchecked")
    @Override
    public Pager searchListPage(Pager page) throws BaseException {
        if (null == page) page = new Pager();

        AuditReturnVisitQueryCondition condition = (AuditReturnVisitQueryCondition) page.getCondition();
        //封装请求参数
        AudReturnVisitPageRequest pageRequest = new AudReturnVisitPageRequest(condition,
                CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), page.getCurrentPage(), page.getEveryPage());
        BaseLogUtils.info(logger, "searchListPage", "searchAudReturnVisitListPage查询请求："+JSON.toJSONString(pageRequest), CurrentThreadContext.getCurrentUserName());
        ResponseData<AudReturnVisitPageReponseDTO> pageResponse = auditReturnVisitService.searchAudReturnVisitListPage(pageRequest);
        BaseLogUtils.info(logger, "searchListPage", "searchAudReturnVisitListPage查询结果："+JSON.toJSONString(pageResponse), CurrentThreadContext.getCurrentUserName());
        AudReturnVisitPageReponseDTO data = new AudReturnVisitPageReponseDTO();
        if (pageResponse != null && ResponseData.SUCCESS_CODE.equals(pageResponse.getCode()) && pageResponse.getData() != null) {
            data = pageResponse.getData();
        }
        List<AuditReturnVisitDTO> DTOList = data.getAudReturnVisitDTOS();
        List<AudReturnVisitVO> VOList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(DTOList)) {
            for (AuditReturnVisitDTO dto : DTOList) {
                AudReturnVisitVO vo = new AudReturnVisitVO();
                BeanUtils.copyProperties(dto, vo);
                vo.setPotionCfg(dto.getOptionCfg());
                vo.setHandingMode(dto.getHandlingMode());
                vo.setLastAuditorNm(dto.getLastAuditorName());
                vo.setAuditorId(dto.getAuditorId());
                vo.setAuditorName(dto.getAuditorName());
                //农机回访扩展信息
                if (dto.getAudVisitAgriculturalDTO() != null) {
                    AudVisitAgriculturalVO audVisitAgriculturalVO = new AudVisitAgriculturalVO();
                    BeanUtils.copyProperties(dto.getAudVisitAgriculturalDTO(), audVisitAgriculturalVO);
                    vo.setAudVisitAgriculturalVO(audVisitAgriculturalVO);
                }
                //乘用车回访扩展信息
                if (dto.getAudVisitCarDTO() != null) {
                    AudVisitCarVO audVisitCarVO = new AudVisitCarVO();
                    BeanUtils.copyProperties(dto.getAudVisitCarDTO(), audVisitCarVO);
                    vo.setAudVisitCarVO(audVisitCarVO);
                }
                //卡车回访扩展信息
                if (dto.getAudVisitTkDTO() != null) {
                    AudVisitTkVO audVisitTkVO = new AudVisitTkVO();
                    BeanUtils.copyProperties(dto.getAudVisitTkDTO(), audVisitTkVO);
                    vo.setAudVisitTkVO(audVisitTkVO);
                }
                //回访记录
                AuditVisitRecordDTO tenantVisitRecordDTO = dto.getTenantVisitRecordDTO();
                if (tenantVisitRecordDTO != null) {
                    AudVisitRecordVO tenantVisitRecordVO = new AudVisitRecordVO();
                    BeanUtils.copyProperties(tenantVisitRecordDTO, tenantVisitRecordVO);
                    tenantVisitRecordVO.setAccountManagerNm(tenantVisitRecordDTO.getAccountManagerName());
                    tenantVisitRecordVO.setAuditorNm(tenantVisitRecordDTO.getAuditorName());
                    tenantVisitRecordVO.setLastAuditorNm(tenantVisitRecordDTO.getLastAuditorName());
                    vo.setTenantVisitRecordVO(tenantVisitRecordVO);
                }
                VOList.add(vo);
            }
        }

        if (CollectionUtils.isNotEmpty(VOList)) {
            for (AudReturnVisitVO audReturnVisitVO : VOList) {
                //金额显示转换
                if (null != audReturnVisitVO.getSubsidyAmt()) {
                    audReturnVisitVO.setSubsidyAmt(DecimalUtils.div(audReturnVisitVO.getSubsidyAmt(), 100));
                }
                if (null != audReturnVisitVO.getDealerAmt()) {
                    audReturnVisitVO.setDealerAmt(DecimalUtils.div(audReturnVisitVO.getDealerAmt(), 100));
                }
                if (null != audReturnVisitVO.getFinancingAmt()) {
                    audReturnVisitVO.setFinancingAmt(DecimalUtils.div(audReturnVisitVO.getFinancingAmt(), 100));
                }
                if (null != audReturnVisitVO.getSmallRepaymentAmt()) {
                    audReturnVisitVO.setSmallRepaymentAmt(DecimalUtils.div(audReturnVisitVO.getSmallRepaymentAmt(), 100));
                }
                if (null != audReturnVisitVO.getLargeRepaymentAmt()) {
                    audReturnVisitVO.setLargeRepaymentAmt(DecimalUtils.div(audReturnVisitVO.getLargeRepaymentAmt(), 100));
                }
                if (null != audReturnVisitVO.getYearNetAmt()) {
                    audReturnVisitVO.setYearNetAmt(DecimalUtils.div(audReturnVisitVO.getYearNetAmt(), 100));
                }
                if (null != audReturnVisitVO.getYearCostAmt()) {
                    audReturnVisitVO.setYearCostAmt(DecimalUtils.div(audReturnVisitVO.getYearCostAmt(), 100));
                }
                if (null != audReturnVisitVO.getYearDominateAmt()) {
                    audReturnVisitVO.setYearDominateAmt(DecimalUtils.div(audReturnVisitVO.getYearDominateAmt(), 100));
                }
                AudVisitAgriculturalVO audVisitAgriculturalVO = audReturnVisitVO.getAudVisitAgriculturalVO();
                if (null != audVisitAgriculturalVO) {
                    if (null != audVisitAgriculturalVO.getNetIncome()) {
                        audVisitAgriculturalVO.setNetIncome(DecimalUtils.div(audVisitAgriculturalVO.getNetIncome(), 100));
                    }
                    if (null != audVisitAgriculturalVO.getContractPrice()) {
                        audVisitAgriculturalVO.setContractPrice(DecimalUtils.div(audVisitAgriculturalVO.getContractPrice(), 100));
                    }
                    if (null != audVisitAgriculturalVO.getSalePrice()) {
                        audVisitAgriculturalVO.setSalePrice(DecimalUtils.div(audVisitAgriculturalVO.getSalePrice(), 100));
                    }
                    if (null != audVisitAgriculturalVO.getPerMuGrossAmt()) {
                        audVisitAgriculturalVO.setPerMuGrossAmt(DecimalUtils.div(audVisitAgriculturalVO.getPerMuGrossAmt(), 100));
                    }
                    if (null != audVisitAgriculturalVO.getPerMuInvestmentAmt()) {
                        audVisitAgriculturalVO.setPerMuInvestmentAmt(DecimalUtils.div(audVisitAgriculturalVO.getPerMuInvestmentAmt(), 100));
                    }
                    if (null != audVisitAgriculturalVO.getPemMuNetAmt()) {
                        audVisitAgriculturalVO.setPemMuNetAmt(DecimalUtils.div(audVisitAgriculturalVO.getPemMuNetAmt(), 100));
                    }
                    if (null != audVisitAgriculturalVO.getNetIncome2()) {
                        audVisitAgriculturalVO.setNetIncome2(DecimalUtils.div(audVisitAgriculturalVO.getNetIncome2(), 100));
                    }
                    if (null != audVisitAgriculturalVO.getSumIncome()) {
                        audVisitAgriculturalVO.setSumIncome(DecimalUtils.div(audVisitAgriculturalVO.getSumIncome(), 100));
                    }
                }
                AudVisitCarVO audVisitCarVO = audReturnVisitVO.getAudVisitCarVO();
                if (null != audVisitCarVO) {
                    if (null != audVisitCarVO.getMonthIncome()) {
                        audVisitCarVO.setMonthIncome(DecimalUtils.div(audVisitCarVO.getMonthIncome(), 100));
                    }
                }
            }
        }
        page.setResultList(VOList);
        page.setTotalCount(data.getTotalCount());
        return page;
    }

    //******************************************私有方法*********************************/
    /**
     * 根据字典中代码组值获取组员集合
     * @param grpCd 代码组值
     * @return 集合
     */
    private List<KeyValueVO> getKvList(String grpCd){
        List<KeyValueVO> kvList = new ArrayList<>();
        try {
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
            if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    kvList.add(keyValueVO);
                }
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return kvList;
    }

	@Override
	public List<KeyValueVO> searchPersonnelTypeCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_PERSONNEL_TYPE_CD);
	}

	@Override
	public List<KeyValueVO> searchYesOrNoTypeCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_SYS_YES_NO_CD);
	}

	@Override
	public List<KeyValueVO> searchReturnVisitConfirmCdList()
			throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_RETURN_VISIT_CONFIRM_CD);
	}

	@Override
	public List<KeyValueVO> searchPickCardCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_PICK_CARD_CD);
	}

	@Override
	public List<KeyValueVO> searchStatusCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_STATUS_CD);
	}

	@Override
	public List<KeyValueVO> searchRelationshipCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_GRP_RL_TYP_CD);
	}

    @Override
    public AudReturnVisitVO selectByProjectIdAndProIntId(Long projectId) throws BaseException {
		if(null==projectId){
			BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "参数不完整", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AudReturnVisitQueryCondition qc = new AudReturnVisitQueryCondition();
		qc.setProjectId(projectId);
		List<AudReturnVisitDTO> DTOList = this.auditApiService.searchAudReturnVisitList(qc,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		AudReturnVisitVO audReturnVisitVO = new AudReturnVisitVO();
		if(CollectionUtils.isNotEmpty(DTOList)){
			audReturnVisitVO = AudReturnVisitVOTransform.toVO(DTOList.get(0));
			//设置承租人回访记录
			List<AudVisitRecordVO> audVisitRecordVOList = audReturnVisitVO.getAudVisitRecordVOList();
			if(CollectionUtils.isNotEmpty(audVisitRecordVOList)){
				for (AudVisitRecordVO audVisitRecordVO : audVisitRecordVOList) {
					if(AudStandingBookConstant.AUD_VISIT_TYP_CD_TEN.equals(audVisitRecordVO.getVisitTypeCd())){
						audReturnVisitVO.setTenantVisitRecordVO(audVisitRecordVO);
						break;
					}
				}
			}
			//金额显示转换
			/*if(null!=audReturnVisitVO.getMainMarketPrice()){
				audReturnVisitVO.setMainMarketPrice(DecimalUtils.div(audReturnVisitVO.getMainMarketPrice(), 100));
			}
			if(null!=audReturnVisitVO.getTruncMarketPrice()){
				audReturnVisitVO.setTruncMarketPrice(DecimalUtils.div(audReturnVisitVO.getTruncMarketPrice(), 100));
			}
			if(null!=audReturnVisitVO.getMonthRepayment()){
				audReturnVisitVO.setMonthRepayment(DecimalUtils.div(audReturnVisitVO.getMonthRepayment(), 100));
			}*/
			if(null!=audReturnVisitVO.getSubsidyAmt()){
				audReturnVisitVO.setSubsidyAmt(DecimalUtils.div(audReturnVisitVO.getSubsidyAmt(), 100));
			}
			if(null!=audReturnVisitVO.getDealerAmt()){
				audReturnVisitVO.setDealerAmt(DecimalUtils.div(audReturnVisitVO.getDealerAmt(), 100));
			}
			if(null!=audReturnVisitVO.getFinancingAmt()){
				audReturnVisitVO.setFinancingAmt(DecimalUtils.div(audReturnVisitVO.getFinancingAmt(), 100));
			}
			if(null!=audReturnVisitVO.getSmallRepaymentAmt()){
				audReturnVisitVO.setSmallRepaymentAmt(DecimalUtils.div(audReturnVisitVO.getSmallRepaymentAmt(), 100));
			}
			if(null!=audReturnVisitVO.getLargeRepaymentAmt()){
				audReturnVisitVO.setLargeRepaymentAmt(DecimalUtils.div(audReturnVisitVO.getLargeRepaymentAmt(), 100));
			}
			if(null!=audReturnVisitVO.getYearNetAmt()){
				audReturnVisitVO.setYearNetAmt(DecimalUtils.div(audReturnVisitVO.getYearNetAmt(), 100));
			}
			if(null!=audReturnVisitVO.getYearCostAmt()){
				audReturnVisitVO.setYearCostAmt(DecimalUtils.div(audReturnVisitVO.getYearCostAmt(), 100));
			}
			if(null!=audReturnVisitVO.getYearDominateAmt()){
				audReturnVisitVO.setYearDominateAmt(DecimalUtils.div(audReturnVisitVO.getYearDominateAmt(), 100));
			}
			AudVisitAgriculturalVO audVisitAgriculturalVO = audReturnVisitVO.getAudVisitAgriculturalVO();
			if(null!=audVisitAgriculturalVO){
				if(null!=audVisitAgriculturalVO.getNetIncome()){
					audVisitAgriculturalVO.setNetIncome(DecimalUtils.div(audVisitAgriculturalVO.getNetIncome(), 100));
				}
				if(null!=audVisitAgriculturalVO.getContractPrice()){
					audVisitAgriculturalVO.setContractPrice(DecimalUtils.div(audVisitAgriculturalVO.getContractPrice(), 100));
				}
				if(null!=audVisitAgriculturalVO.getSalePrice()){
					audVisitAgriculturalVO.setSalePrice(DecimalUtils.div(audVisitAgriculturalVO.getSalePrice(), 100));
				}
				if(null!=audVisitAgriculturalVO.getPerMuGrossAmt()){
					audVisitAgriculturalVO.setPerMuGrossAmt(DecimalUtils.div(audVisitAgriculturalVO.getPerMuGrossAmt(), 100));
				}
				if(null!=audVisitAgriculturalVO.getPerMuInvestmentAmt()){
					audVisitAgriculturalVO.setPerMuInvestmentAmt(DecimalUtils.div(audVisitAgriculturalVO.getPerMuInvestmentAmt(), 100));
				}
				if(null!=audVisitAgriculturalVO.getPemMuNetAmt()){
					audVisitAgriculturalVO.setPemMuNetAmt(DecimalUtils.div(audVisitAgriculturalVO.getPemMuNetAmt(), 100));
				}
				if(null!=audVisitAgriculturalVO.getNetIncome2()){
					audVisitAgriculturalVO.setNetIncome2(DecimalUtils.div(audVisitAgriculturalVO.getNetIncome2(), 100));
				}
				if(null!=audVisitAgriculturalVO.getSumIncome()){
					audVisitAgriculturalVO.setSumIncome(DecimalUtils.div(audVisitAgriculturalVO.getSumIncome(), 100));
				}
			}
			AudVisitCarVO audVisitCarVO = audReturnVisitVO.getAudVisitCarVO();
			if(null!=audVisitCarVO){
				if(null!=audVisitCarVO.getMonthIncome()){
					audVisitCarVO.setMonthIncome(DecimalUtils.div(audVisitCarVO.getMonthIncome(), 100));
				}
			}
		}else{
			//设置  融资期限/月还款/挂靠公司名称/担保人关系/担保人备注/紧急联系人关系/紧急联系人备注
			/**项目报价方案信息*/
			try {
				PrjQuatPrpsQueryCondition quatQC = new PrjQuatPrpsQueryCondition();
				quatQC.setIsFormalPrps(BaseConstant.IS_YESNO_YES);
				quatQC.setPrjId(projectId);
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询项目报价方案Start===quatQC:"+JSON.toJSONString(quatQC));
				List<PrjQuatPrpsVO> quatList = this.prjQuatPrpsService.searchList(quatQC);
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询项目报价方案End===quatList:"+JSON.toJSONString(quatList));
				if(CollectionUtils.isNotEmpty(quatList)){
					PrjQuatPrpsVO prjQuatPrpsVO = quatList.get(0);
					if(null!=prjQuatPrpsVO){
						if(StringUtils.isNotEmpty(prjQuatPrpsVO.getLsPd()) && StringUtils.isNotEmpty(prjQuatPrpsVO.getLsPdUntCdNm())){
							audReturnVisitVO.setLeaseTerm(prjQuatPrpsVO.getLsPd()+prjQuatPrpsVO.getLsPdUntCdNm());//融资期限
						}
						if(null!=prjQuatPrpsVO.getEachEstRntAmt()){
							audReturnVisitVO.setMonthRepayment(String.valueOf(DecimalUtils.div(prjQuatPrpsVO.getEachEstRntAmt(), 100)));//月还款
						}
					}
				}
				/**项目产品明细列表*/
				PrjPrdDtlQueryCondition prjPrdDtlQC = new PrjPrdDtlQueryCondition();
				prjPrdDtlQC.setPrjId(projectId);
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询项目产品明细Start===prjPrdDtlQC:"+JSON.toJSONString(prjPrdDtlQC));
				List<PrjPrdDtlVO> prjPrdDtlVOList = this.prjPrdDtlService.selectList(prjPrdDtlQC);
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询项目产品明细End===prjPrdDtlVOList:"+JSON.toJSONString(prjPrdDtlVOList));
				List<String> companyNmList = new ArrayList<String>();
				String companyNmString = "";
				if(CollectionUtils.isNotEmpty(prjPrdDtlVOList)){
					for (PrjPrdDtlVO prjPrdDtlVO : prjPrdDtlVOList) {
						if(null!=prjPrdDtlVO && StringUtils.isNotEmpty(prjPrdDtlVO.getLnkCompNm()) && !companyNmList.contains(prjPrdDtlVO.getLnkCompNm())){
							companyNmList.add(prjPrdDtlVO.getLnkCompNm());
						}
					}
					if(CollectionUtils.isNotEmpty(companyNmList)){
						for (String string : companyNmList) {
							companyNmString+=string;
							companyNmString+="；";
						}
					}
				}
				if(StringUtils.isNotEmpty(companyNmString)){
					audReturnVisitVO.setAffiliatedCompany(companyNmString);
				}
				/**担保人*/
				String guraRl = "";
				String guraRem = "";
				PrjCstBscInfoQueryCondition guarantorQC = new PrjCstBscInfoQueryCondition();
				guarantorQC.setPrjId(Long.valueOf(projectId));
				guarantorQC.setCstRlTyp(PrjCstBscInfoConstant.CST_Rl_ATTR_GUARANTOR);
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询项目担保人Start===guarantorQC:"+JSON.toJSONString(guarantorQC));
				List<PrjCstBscInfoVO> guarantorList = this.prjCstBscInfoService.searchList(guarantorQC);
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询项目担保人End===guarantorList:"+JSON.toJSONString(guarantorList));
				if(CollectionUtils.isNotEmpty(guarantorList)){
					this.setDictData(guarantorList);
					for (PrjCstBscInfoVO prjCstBscInfoVO : guarantorList) {
						if(StringUtils.isNotEmpty(prjCstBscInfoVO.getRlCdNm())){
							guraRl += prjCstBscInfoVO.getRlCdNm();
							guraRl += "；";
						}
						if(StringUtils.isNotEmpty(prjCstBscInfoVO.getCstNm())){
							guraRem += prjCstBscInfoVO.getCstNm();
							guraRem += "；";
						}
					}
				}
				audReturnVisitVO.setGuraRl(guraRl);
				audReturnVisitVO.setGuraRem(guraRem);
				/**紧急联系人*/
				String ugRl = "";
				String ugRem = "";
				PrjLinkManQueryCondition plmQC = new PrjLinkManQueryCondition();
				plmQC.setPrjId(projectId);
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询项目紧急联系人Start===plmQC:"+JSON.toJSONString(plmQC));
				List<PrjLinkManVO> ugList = this.prjLinkManService.searchList(plmQC);
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询项目紧急联系人End===ugList:"+JSON.toJSONString(ugList));
				if(CollectionUtils.isNotEmpty(ugList)){
					for (PrjLinkManVO prjLinkManVO : ugList) {
						if(StringUtils.isNotEmpty(prjLinkManVO.getRlCdNm())){
							ugRl += prjLinkManVO.getRlCdNm();
							ugRl += "；";
						}
						if(StringUtils.isNotEmpty(prjLinkManVO.getLnkNm())){
							ugRem += prjLinkManVO.getLnkNm();
							ugRem += "；";
						}
					}
				}
				audReturnVisitVO.setUgRl(ugRl);
				audReturnVisitVO.setUgRem(ugRem);
			} catch (Exception e) {
				BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "===查询回访信息异常===Detail:"+e.getMessage());
			BaseLogUtils.error(logger, "-", "异常", e);
			}
		}
		return audReturnVisitVO;
    }

    private void setDictData(List<PrjCstBscInfoVO> list){
        if(CollectionUtils.isEmpty(list)) return;
        Map<String, String> rlTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_GRP_RL_TYP_CD);
        if(null!=rlTypCdMap){
            for (PrjCstBscInfoVO prjCstBscInfoVO : list) {
                if(rlTypCdMap.containsKey(prjCstBscInfoVO.getRlCd())){
                    prjCstBscInfoVO.setRlCdNm(rlTypCdMap.get(prjCstBscInfoVO.getRlCd()));
                }
            }
        }

    }

	/*@Override
	public String previewGuarantorRem(Long projectId) throws BaseException {
		if(StringUtils.isEmpty(projectId)){
			return "";
		}
		StringBuffer previewGuarantorRem = new StringBuffer("");
		PrjCstBscInfoQueryCondition guarantorQC = new PrjCstBscInfoQueryCondition();
		guarantorQC.setPrjId(Long.valueOf(projectId));
		guarantorQC.setCstRlTyp(PrjCstBscInfoConstant.CST_Rl_ATTR_GUARANTOR);
		List<PrjCstBscInfoVO> guarantorList = this.prjCstBscInfoService.searchList(guarantorQC);
		if(CollectionUtils.isNotEmpty(guarantorList)){
			for (PrjCstBscInfoVO prjCstBscInfoVO : guarantorList) {
				Long guaCstId = prjCstBscInfoVO.getCstId();
				if(null!=prjCstBscInfoVO){
					CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectDetailById(guaCstId);//客户信息
					if(null!=cstBscInfoVO){
						CstNpBscInfoVO cstNpBscInfoVO = cstBscInfoVO.getCstNpBscInfoVO();//自然人信息
						//CstCorpBscInfoVO cstCorpBscInfoVO = cstBscInfoVO.getCstCorpBscInfoVO();//法人信息
						if(CustomerConstant.CST_TYP_CD_NP.equals(cstBscInfoVO.getCstTypCd())){
							previewGuarantorRem.append("自然人姓名:");
							if(StringUtils.isNotEmpty(cstBscInfoVO.getCstNm())){
								previewGuarantorRem.append(cstBscInfoVO.getCstNm()+";");
							}
							previewGuarantorRem.append("自然人工作单位:");
							if(null!=cstNpBscInfoVO && StringUtils.isNotEmpty(cstNpBscInfoVO.getWorkPlc())){
								previewGuarantorRem.append(cstNpBscInfoVO.getWorkPlc()+";");
							}
						}else{
							previewGuarantorRem.append("法人公司名称:");
							if(StringUtils.isNotEmpty(cstBscInfoVO.getCstNm())){
								previewGuarantorRem.append(cstBscInfoVO.getCstNm()+";");
							}
						}
					}
				}
			}
		}
		return previewGuarantorRem.toString();
	}*/

	/*@Override
	public List<KeyValueVO> searchProfitCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_PROFIT_CD);
	}*/

	@Override
	public List<KeyValueVO> searchProfitCdList(String sysCd, String orgCd) throws BaseException {
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(sysCd,
					orgCd, DictionaryConstant.CODE_AUD_PROFIT_CD);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getKvList", "获取字典项组"+DictionaryConstant.CODE_AUD_PROFIT_CD+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getKvList", "获取字典项组"+DictionaryConstant.CODE_AUD_PROFIT_CD+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}

	@Override
	public List<KeyValueVO> searchBizExpList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_BIZ_EXP);
	}

	@Override
	public List<KeyValueVO> searchGoodsResList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_GOODS_RES);
	}

	@Override
	public List<KeyValueVO> searchGdsStlWayCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_GDS_STL_WAY_CD);
	}

	@Override
	public List<KeyValueVO> searchDriverList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_DRIVER);
	}

	@Override
	public List<KeyValueVO> searchSecondPayResCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_OPERATION_EXPERIENCE_CD);
	}

	@Override
	public List<KeyValueVO> searchAgentCardStateCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_AGENT_CARD_STATE_CD);
	}

	@Override
	public List<KeyValueVO> searchEqmtAddressCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_EQMT_ADDRESS_CD);
	}

	@Override
	public List<KeyValueVO> searchVehiclesDoorCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_VEHICLES_DOOR_CD);
	}

	@Override
	public List<KeyValueVO> searchPowerCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_POWER_NO);
	}
	@Override
	public List<KeyValueVO> searchCircuitTypeList() throws BaseException {
		return this.getKvList(DictionaryConstant.CIRCUIT_TYPE);
	}
	@Override
	public List<KeyValueVO> searchHanglingModeList() throws BaseException {
		return this.getKvList(DictionaryConstant.HANDLING_MODE);
	}

	@Override
	public List<AudOpeLineVO> selectByAudOpeLine(Long id) throws BaseException {
		List<AudOpeLineDTO> selectByAudOpeLine = this.auditApiService.selectByAudOpeLine(id);
		return	AudOpeLineVOTransform.toVOList(selectByAudOpeLine);
	}

	@Override
	public void modifvisitStatus(AudReturnVisitVO audReturnVisitVO)throws BaseException {
		if(null == audReturnVisitVO){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
		}
		this.auditApiService.modifvisitStatus(AudReturnVisitVOTransform.toDTO(audReturnVisitVO));

	}

	@Override
	public Long addOnlyAudReturnVisit(AudReturnVisitVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.auditApiService.addAudReturnVisit(AudReturnVisitVOTransform.toDTO(entity));
	}
	@Override
	public AudReturnVisitVO selectByProjectId(Long projectId) throws BaseException {
		if(null==projectId){
			BaseLogUtils.info(logger, "selectByProjectIdAndProIntId", "参数不完整", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AudReturnVisitQueryCondition qc = new AudReturnVisitQueryCondition();
		qc.setProjectId(projectId);
		List<AudReturnVisitDTO> DTOList = this.auditApiService.searchAudReturnVisitList(qc,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		AudReturnVisitVO audReturnVisitVO = new AudReturnVisitVO();
		if(CollectionUtils.isNotEmpty(DTOList)){
			audReturnVisitVO = AudReturnVisitVOTransform.toVO(DTOList.get(0));
			//设置承租人回访记录
			List<AudVisitRecordVO> audVisitRecordVOList = audReturnVisitVO.getAudVisitRecordVOList();
			if(CollectionUtils.isNotEmpty(audVisitRecordVOList)){
				for (AudVisitRecordVO audVisitRecordVO : audVisitRecordVOList) {
					if(AudStandingBookConstant.AUD_VISIT_TYP_CD_TEN.equals(audVisitRecordVO.getVisitTypeCd())){
						audReturnVisitVO.setTenantVisitRecordVO(audVisitRecordVO);
						break;
					}
				}
			}
			//金额显示转换
			/*if(null!=audReturnVisitVO.getMainMarketPrice()){
				audReturnVisitVO.setMainMarketPrice(DecimalUtils.div(audReturnVisitVO.getMainMarketPrice(), 100));
			}
			if(null!=audReturnVisitVO.getTruncMarketPrice()){
				audReturnVisitVO.setTruncMarketPrice(DecimalUtils.div(audReturnVisitVO.getTruncMarketPrice(), 100));
			}
			if(null!=audReturnVisitVO.getMonthRepayment()){
				audReturnVisitVO.setMonthRepayment(DecimalUtils.div(audReturnVisitVO.getMonthRepayment(), 100));
			}*/
			if(null!=audReturnVisitVO.getSubsidyAmt()){
				audReturnVisitVO.setSubsidyAmt(DecimalUtils.div(audReturnVisitVO.getSubsidyAmt(), 100));
			}
			if(null!=audReturnVisitVO.getDealerAmt()){
				audReturnVisitVO.setDealerAmt(DecimalUtils.div(audReturnVisitVO.getDealerAmt(), 100));
			}
			if(null!=audReturnVisitVO.getFinancingAmt()){
				audReturnVisitVO.setFinancingAmt(DecimalUtils.div(audReturnVisitVO.getFinancingAmt(), 100));
			}
			if(null!=audReturnVisitVO.getSmallRepaymentAmt()){
				audReturnVisitVO.setSmallRepaymentAmt(DecimalUtils.div(audReturnVisitVO.getSmallRepaymentAmt(), 100));
			}
			if(null!=audReturnVisitVO.getLargeRepaymentAmt()){
				audReturnVisitVO.setLargeRepaymentAmt(DecimalUtils.div(audReturnVisitVO.getLargeRepaymentAmt(), 100));
			}
			if(null!=audReturnVisitVO.getYearNetAmt()){
				audReturnVisitVO.setYearNetAmt(DecimalUtils.div(audReturnVisitVO.getYearNetAmt(), 100));
			}
			if(null!=audReturnVisitVO.getYearCostAmt()){
				audReturnVisitVO.setYearCostAmt(DecimalUtils.div(audReturnVisitVO.getYearCostAmt(), 100));
			}
			if(null!=audReturnVisitVO.getYearDominateAmt()){
				audReturnVisitVO.setYearDominateAmt(DecimalUtils.div(audReturnVisitVO.getYearDominateAmt(), 100));
			}
		}
		return audReturnVisitVO;
	}

}
